package cn.xz.tipsum.dialog

import android.view.Gravity
import android.widget.TextView
import cn.xz.tipsum.R
import cn.xz.tipsum.base.BaseDialogRxFragment


/**
 * 通用弹窗
 * */
class TipsDialog(private val callback: (isGet: Boolean) -> Unit): BaseDialogRxFragment() {

    private var mS: String = ""
    private var mOk: String = ""
    private var mOn: String = ""

    private var tvCancel: TextView? = null
    private var tvOk: TextView? = null
    private var tvTitle: TextView? = null

    companion object {
        fun newInstance(
            s: String,
            k: String,
            n: String,
            callback: (isGet: Boolean) -> Unit
        ): TipsDialog {
            val mDialog = TipsDialog(callback)
            mDialog.mS = s
            mDialog.mOk = k
            mDialog.mOn = n
            return mDialog
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.dialog_tips
    }

    override fun configDialog() {
        this.setDialogSize(gravity = Gravity.CENTER,width = 350)
    }

    override fun initViews() {

        dialog?.let {
            tvCancel = it.findViewById(R.id.tv_cancel)
            tvOk = it.findViewById(R.id.tv_ok)
            tvTitle = it.findViewById(R.id.tv_title)
        }

        //点击外部不隐藏
        dialog?.setCancelable(false)
        dialog?.setCanceledOnTouchOutside(false)

        tvTitle?.text = mS
        tvOk?.text = mOk
        tvCancel?.text = mOn

        tvOk?.setOnClickListener {
            callback.invoke(true)
            dismiss()
        }
        tvCancel?.setOnClickListener {
            callback.invoke(false)
            dismiss()
        }
    }


}